package com.xw.mailservice.service;

import java.io.File;
import java.io.IOException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 郭飞鹏
 * @date 2017年4月13日 下午3:31:04
 */
@Service
public class FileService {

	@Value("${upload.file.path}")
	private String uploadFilePath;
	
	public String[] saveFiles(MultipartFile... files) throws IOException {
		String savePath = System.getProperty("web.root")+File.separator+uploadFilePath;
		savePath = savePath.replace(File.separator+File.separator, File.separator);
		File filePath = new File(savePath);
		if(!filePath.exists()){
			filePath.mkdirs();
		}
		String[] attachfiles = new String[files.length];
		for(int i = 0; i<files.length; i++){
			String filepath = savePath + File.separator + files[i].getOriginalFilename();
			files[i].transferTo(new File(filepath));
			attachfiles[i] = filepath;
		}
		return attachfiles;
	}

}
